package cn.t.modules.scheduler.common.data;

import lombok.Getter;

/**
 * @author 陶敏麒
 * @date 2023/5/8 10:06
 */
@Getter
public class R<T> {
    /**
     * 响应信息状态码
     */
    private final Integer code;
    /**
     * 响应信息提示语
     */
    private final String msg;
    /**
     * 响应信息数据体
     */
    private final T data;

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R<Object> ok() {
        return new R<>(0, "", null);
    }

    public static R<Object> okWithMsg(String msg) {
        return new R<>(0, msg, null);
    }

    public static <T> R<T> ok(T data) {
        return new R<>(0, "", data);
    }

    public static R<Object> error(String msg) {
        return new R<>(1, msg, null);
    }
    public static R<Object> error(int code, String msg) {
        return new R<>(code, msg, null);
    }

    public static <T> R<T> error(int code, String msg, T data) {
        return new R<>(code, msg, data);
    }

}
